package com.shr.xsunmvc;

import javax.servlet.ServletContext;

import com.shr.xsunmvc.servlet.packer.Request;
import com.shr.xsunmvc.servlet.packer.Response;

/**
 * 当前线程的上下文环境
 * @author sun haoran
 *
 */
public class XsunContext {
	private static final ThreadLocal<XsunContext> CONTEXT = new ThreadLocal<>() ;
	
	private ServletContext servletContext ;
	private Request request ;
	private Response response ;
	
	private XsunContext(){};
	
	public static XsunContext me(){
		return CONTEXT.get() ;
	}

	public static void initContext(ServletContext servletContext, Request request, Response response) {
		XsunContext context = new XsunContext() ;
		context.request = request ;
		context.response = response ;
		context.servletContext = servletContext ;
		CONTEXT.set(context);
	}
	
	public static void remove(){
		CONTEXT.remove();
	}

	public ServletContext getServletContext() {
		return servletContext;
	}

	public void setServletContext(ServletContext servletContext) {
		this.servletContext = servletContext;
	}

	public Request getRequest() {
		return request;
	}

	public void setRequest(Request request) {
		this.request = request;
	}

	public Response getResponse() {
		return response;
	}

	public void setResponse(Response response) {
		this.response = response;
	}
	
	
	
	
}
